﻿
using System;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;
using Arction.Wpf.BindableCharting.SeriesXY;

namespace LightningChartBindingExample
{
    public partial class MainWindow : Window
    {
        public MainViewModel ViewModel { get; set; }

        public MainWindow()
        {
            InitializeComponent();
            ViewModel = new MainViewModel();
            DataContext = ViewModel;
            // 动态添加 PointLineSeries
            ConfigChart(chart);
            AddSeriesToChart();
        }
        
        private void ConfigChart(Arction.Wpf.BindableCharting.LightningChartUltimate chart)
        {
            chart.ColorTheme = Arction.Wpf.BindableCharting.ColorTheme.LightGray;
            chart.Title.Text = "波特图";
            chart.Title.Color = Colors.DeepSkyBlue;
            chart.Padding = new Thickness(0);
            chart.Margin = new Thickness(0);
            chart.ChartBackground.Color = Colors.Transparent;
        }

        private void AddSeriesToChart()
        {
                var viewModel = this.DataContext as MainViewModel;
                if (viewModel != null && viewModel.SeriesCollection.Count > 0)
                {
                    // 设置 Points 数据绑定
                    var bindingPoints = new Binding("SeriesCollection[0].DataPoints")
                    {
                        Source = viewModel,
                        Mode = BindingMode.OneWay
                    };
                    BindingOperations.SetBinding(pointLineSeries, PointLineSeries.PointsProperty, bindingPoints);

                    // 设置 LineStyle 数据绑定
                    var bindingLineStyle = new Binding("SeriesCollection[0].LineStyle")
                    {
                        Source = viewModel,
                        Mode = BindingMode.OneWay
                    };
                    BindingOperations.SetBinding(pointLineSeries, PointLineSeries.LineStyleProperty, bindingLineStyle);

                    // 设置 Title 数据绑定
                    var bindingTitle = new Binding("SeriesCollection[0].Title")
                    {
                        Source = viewModel,
                        Mode = BindingMode.TwoWay
                    };
                    BindingOperations.SetBinding(pointLineSeries, PointLineSeries.TitleProperty, bindingTitle);
                }
            }














            //pointLineSeries = new PointLineSeries
            //{
            //    LineStyle = new Arction.Wpf.BindableCharting.LineStyle() { Color = Color.FromArgb(222, 122, 225, 255) },
            //    Title = new Arction.Wpf.BindableCharting.Titles.SeriesTitle() { Text = "你好" },
            //    Points = ViewModel.SeriesCollection[0].DataPoints
            //};

            //foreach (var series in ViewModel.SeriesCollection)
            //{
            //    // 创建新的 PointLineSeries
            //    var pointLineSeries = new PointLineSeries
            //    {
            //        LineStyle = new Arction.Wpf.BindableCharting.LineStyle() { Color = Color.FromArgb(222,122,225,255) },
            //        Title = new Arction.Wpf.BindableCharting.Titles.SeriesTitle() { Text = "你好" }

            //    };
            //    var pointLineSeries1 = new PointLineSeries
            //    {
            //        LineStyle = new Arction.Wpf.BindableCharting.LineStyle() { Color = Color.FromArgb(222, 122, 225, 122) }
            //    };
            //    pointLineSeries.Points = series.DataPoints;
            //    pointLineSeries1.Points = series.DataPoints;
            //   // 将 PointLineSeries 添加到 chart 的 ViewXY 中
            //    viewXY.PointLineSeries.Add(pointLineSeries);
            //    viewXY.PointLineSeries.Add(pointLineSeries1);
            //}
        
    }
}
